import http from '@/utils/http'
import { type ApiResponse, type SwiperItem, type TravelPost, type PageResponse, type SearchParams, type SearchResponse } from '@/types/http'


import request from '@/config/request'


export function getSpots() {
  return request({
    url: '/getSpots',
    method: 'get',
    headers: {
      'Accept': 'application/json'
    }
  })
}
//精选游记
export function getNotes() {
  return request({
    url: '/getNotes',
    method: 'get',
    headers: {
      'Accept': 'application/json'
    }
  })
}
//热门攻略
export function getGuideList() {
  return request({
    url: '/getGuideList',
    method: 'get',
    headers: {
      'Accept': 'application/json'
    }
  })
}
getGuideList
export function getUserInfo() {
  return request({
    url: '/user/info',
    method: 'get'
  })
}

// 轮播图相关API
export const getSwiperList = (): Promise<ApiResponse<SwiperItem[]>> => {
  return http.get('/getSwiperList')
}




// 获取热门游记
export const getHotPosts = (page: number = 1, pageSize: number = 10): Promise<ApiResponse<PageResponse<TravelPost>>> => {
  return http.get('/posts/hot', { page, pageSize })
}

// 获取游记详情
export const getPostDetail = (id: number): Promise<ApiResponse<TravelPost>> => {
  return http.get(`/posts/${id}`)
}

// 搜索游记
export const searchPosts = (params: SearchParams): Promise<ApiResponse<SearchResponse<TravelPost>>> => {
  return http.get('/posts/search', params)
}

// 获取统计数据
export const getStatistics = (): Promise<ApiResponse<{
  users: number
  posts: number
  destinations: number
  reviews: number
}>> => {
  return http.get('/statistics')
}

// 用户相关API
export const userApi = {
  // 用户登录
  login: (username: string, password: string) => {
    return http.post('/auth/login', { username, password })
  },
  
  // 用户注册
  register: (userData: any) => {
    return http.post('/auth/register', userData)
  },
  
  // 获取用户信息
  getUserInfo: () => {
    return http.get('/user/info')
  },
  
  // 更新用户信息
  updateUserInfo: (userData: any) => {
    return http.put('/user/info', userData)
  }
}

// 文件上传API
export const fileApi = {
  // 上传单个文件
  uploadFile: (file: File) => {
    return http.upload('/upload/file', file)
  },
  
  // 上传多个文件
  uploadFiles: (files: File[]) => {
    return http.uploadMultiple('/upload/files', files)
  },
  
  // 上传图片
  uploadImage: (file: File) => {
    return http.upload('/upload/image', file)
  }
}

// 游记相关API
export const postApi = {
  // 创建游记
  createPost: (postData: Partial<TravelPost>) => {
    return http.post('/posts', postData)
  },
  
  // 更新游记
  updatePost: (id: number, postData: Partial<TravelPost>) => {
    return http.put(`/posts/${id}`, postData)
  },
  
  // 删除游记
  deletePost: (id: number) => {
    return http.delete(`/posts/${id}`)
  },
  
  // 点赞游记
  likePost: (id: number) => {
    return http.post(`/posts/${id}/like`)
  },
  
  // 取消点赞
  unlikePost: (id: number) => {
    return http.delete(`/posts/${id}/like`)
  }
}
